import {Component, Inject, PLATFORM_ID, OnInit} from '@angular/core';
import {isPlatformBrowser, isPlatformServer} from '@angular/common';

export class LocalStorage {
    storageKeyPrefix = 'ngStorage-';
    storageType = 'localstorage';

    constructor(@Inject(PLATFORM_ID) private platformId: Object) {
    }

    getItem(key) {
        if (isPlatformBrowser(this.platformId)) {
            return (window.localStorage.getItem(this.storageKeyPrefix + key));
        } else {
            return this[key];
        }
    }

    setItem(key, value) {
        if (isPlatformBrowser(this.platformId)) {
            window.localStorage.setItem(this.storageKeyPrefix + key, value);
        } else {
            this[key] = value;
        }
    }
}
